package net.controllers;

import java.net.BindException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.model.RectangleReference;
import net.service.RectangleReferenceManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping(value = "/rectangleReference")
public class RectangleReferenceController {
	
	private RectangleReference rectangleReference = null;
	
	@Autowired
	private RectangleReferenceManager rectangleReferenceManagerImpl;

	@RequestMapping(method = RequestMethod.GET)
	public String getUploadForm(Model model) {
		model.addAttribute(rectangleReferenceManagerImpl.getRectangleReference());
		return "/rectanglereference";
	}

	@RequestMapping(method = RequestMethod.POST)
	public String create(RectangleReference rectangleReference,
			HttpServletRequest request, HttpServletResponse response,
			Object command, BindException errors, HttpSession session) {
	
		if (rectangleReference != null) {
			rectangleReferenceManagerImpl.setRectangleReference(rectangleReference);
			this.rectangleReference=rectangleReferenceManagerImpl.getRectangleReference();
		}
		return "redirect:/forms/home";
	}

}
